package com.servlet;

import com.dao.Student;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet("/addtest")
public class AddServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        try {
            increase(req, resp);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);

    }

//增加
    private void increase(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException, SQLException {
        Integer sid = Integer.parseInt(req.getParameter("sid"));
        String studentno = req.getParameter("studentno");
        String sname = req.getParameter("sname");
        String gender = req.getParameter("gender");
        Integer age = Integer.parseInt(req.getParameter("age"));
        String address = req.getParameter("address");
        System.out.println(sid+" "+studentno+" "+sname+" "+gender+" "+age+" "+address);

        Student student = new Student();
        try {
            student.increase(sid,studentno,sname,gender,age,address);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        CheckServlet.check(req, resp);

    }
}
